$(function() {
    $("#menu-primary").each(function() {
        var i = 0;
        var initial = 0;
        if ($(this).hasClass("focus")) {
            initial = $(this).index();
        }
        var $li = $(this).find("li");
        var h = $li.height();
        $(".history-pane").eq(initial).addClass("active").siblings().removeClass("active");
        $li.on("click", function() {
            i = $(this).index();
            // 移动指针
            $("#J_NavLabel").css({
                top: h * i + 'px'
            });
            // 切换tab
            $(".history-pane").eq(i).addClass("active").siblings().removeClass("active");
            return false;
        });
    });

    // 直播历史/全部列表
    $.each($(".history-date"),function() {
        if (!$(".history-broadcast").length) {
            return;
        }
        var $warpEle = $(this),
            $targetA = $warpEle.find(".first a"),
            parentH,
            eleTop = [];

        parentH = $warpEle.parent().parent().height();

        setTimeout(function() {

            $warpEle.parent().animate({
                "height": parentH
            }, 500);

            $warpEle.find("ul").children(":not('h2:first')").addClass("bounceInDown").css({
                "-webkit-animation-duration": "2s",
                "-webkit-animation-delay": "0",
                "-webkit-animation-timing-function": "ease",
                "-webkit-animation-fill-mode": "both"
            }).end().children("h2").css({
                "position": "relative"
            });

        }, 600);

        $targetA.click(function() {
            $(this).parent().css({
                "position": "relative"
            });
            $(this).parent().siblings().slideToggle();
            $warpEle.parent().removeAttr("style");
            return false;
        });
    });

    $(".fixText").each(function(){
        var tempText = $(this).text();
        var maxLength = 120;
        if(tempText.length > maxLength){
            $(this).text(tempText.substring(0,maxLength) + "...");
        }
    });
});
